package com.hks.quart.utils;

/**
 * 请求结果状态枚举常量类
 *
 * @author lqzhang
 */
public enum HttpStatus {

    SUCCESS(200, "请求成功"),

    NO_DATA(201, "没有查询到对应的数据"),

    FAIL(203, "请求异常"),

    PARAM_ERROR(204, "参数名错误或参数为空，请检查"),

    NO_LOGIN(205, "没有授权"),

    SAVE_ERROR(206, "操作失败"),

    NO_DATA_IN_AUTH(207, "权限范围内没有查询到数据"),

    ARREARS(208, "账户可用余额已不足，请充值"),

    UNBOUND_PHONE(210, "用户账户未绑定微信手机"),

    USER_NOT_EXITS(211, "用户不存在"),

    PASSWORD_ERROR(212, "密码错误"),

    TOKEN_EXPIRED(403, "当前登录凭证已失效，请重新登录"),

    SERVICE_NOT_OPENED(215, "该功能未开通，联系管理员开通使用"),;

    /**
     * 状态码
     */
    private int code;
    /**
     * 状态信息
     */
    private String message;

    HttpStatus(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public int getStatusTypeCode(HttpStatus httpStatus) {
        return httpStatus.getCode();
    }

    public String getStatusTypeMessage(HttpStatus httpStatus) {
        return httpStatus.getMessage();
    }

    public static HttpStatus getStatusTypeByCode(int code) {
        HttpStatus httpStatus = null;
        for (HttpStatus status : values()) {
            if (status.getCode() == code) {
                httpStatus = status;
                break;
            }
        }
        return httpStatus;
    }

    public static HttpStatus getStatusTypeByMessage(String message) {
        HttpStatus httpStatus = null;
        for (HttpStatus status : values()) {
            if (status.getMessage().equals(message)) {
                httpStatus = status;
                break;
            }
        }
        return httpStatus;
    }

}
